import React, { PureComponent } from 'react';
import { Carousel, Row, Col, List, Avatar, Card, message, Table, Button,Tabs, Select  } from 'antd';
import axios from 'axios';
import './psy.css';
export default class Admin extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            data: []
        }
    }
    componentDidMount() {
        this.getAdmin();
    }
    getAdmin = () => {
        axios({
            method: 'post',
            url: 'http://localhost:8080/psy/getAll',
            data:{token:sessionStorage.getItem("token")}
        }).then((res) => {
            console.log(res);
            res.data.data.forEach((item, index) => {
                item.index = index;
            });
            this.setState({
                data: res.data.data
            })
        }).catch((err) => {
            message.error('获取信息失败请检查网络')
            throw err;
        })
    }
    addDocter = (data) => {
        axios({
            method: '',
            url: '',
            data
        }).then((res) => {
            console.log(res);
            if (res.data.status === 'ok') {
                message.success('操作成功');
                this.getAdmin();
            } else {
                message.error('操作失败,请检查信息');
            }
        }).catch((err) => {
            console.log(err);
            message.error('操作失败请检查网络')
        })
    }
    delAdmin = (id) => {
        axios({
            method: 'post',
            url: '',
            params: { id }
        }).then((res) => {
            console.log(res);
            if (res.data.status === 'ok') {
                message.success('操作成功');
                this.getDocter();
            } else {
                message.error('操作失败,请检查信息');
            }
        }).catch((err) => {
            console.log(err);
            message.error('操作失败请检查网络')
        })
    }
    render() {
        const data = [
            {
                id: 'asdasda',
                title: 'Ant Design Title 1',
            },
            {
                id: 'asdasda',
                title: 'Ant Design Title 2',
            },
            {
                id: 'asdasda',
                title: 'Ant Design Title 3',
            },
            {
                id: 'asdasda',
                title: 'Ant Design Title 4',
            },
        ];
        const columns = [
                // {
                //   title: '用户ID',
                //   dataIndex: 'id',
                //   key: 'id',
                // },
                {
                    title: '序号',
                    dataIndex: 'id',
                    key: 'id',
                }, {
                    title: '类型',
                    dataIndex: 'type',
                    key: 'type',
                }, {
                    title: '描述',
                    dataIndex: 'word',
                    key: 'word',
                }, {
                    title: '操作',
                    render: (text, record) => {
                        return (<div><Button>编辑</Button><Button>删除</Button></div>)
                    }
                }]
        return (<div>
            <div className='action'>
                    <Table
                        dataSource={this.state.data}
                        columns={columns}
                        pagination={{
                            total: this.state.length,
                            showTotal: total => `总共 ${total} 条记录`,
                            showSizeChanger: true,
                            showQuickJumper: true,
                            pageSizeOptions: ['5', '10', '20', '30'],
                            hideOnSinglePage: true,

                        }}  />
            </div>
        </div>);
    }
}